/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import org.jsoup.Jsoup;

import javax.swing.*;

/**
 * <p>Description:此软件什么功能</p>
 * <p>Class: Dict
 * <p>Powered by webrx On 2023-07-05 14:35
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Dict {
    public static void main(String[] args) throws Exception {
        while (true) {
            //1 输入词汇
            var w = JOptionPane.showInputDialog("请输入词汇：");
            if (w == null || w.trim().length() == 0) {
                break;
            }

            //2 组合网址http://cn.bing.com/dict/s?q=
            var u = "http://cn.bing.com/dict/s?q=" + w;

            //3 jsoup组件获取结果
            var ss = Jsoup.connect(u).get().select("span[class=def b_regtxt]").eachText();
            var su = new StringBuilder();
            var i = 0;
            for (String s : ss) {
                su.append(String.format("%02d、", ++i)).append(s).append("\r\n");
            }
            //4 输出结果
            JOptionPane.showMessageDialog(null, su);
        }
        //System.out.println("词典软件退出");
        System.exit(0);
    }
}
